Skip to content

feat(timescaledb): 支持配置TimescaleDB函数所在的schema - #710

Merged
zhou-hao merged 3 commits into
jetlinks:2.11from
PengyuDeng:feature
Nov 5, 2025
Merged

feat(timescaledb): 支持配置TimescaleDB函数所在的schema#710
zhou-hao merged 3 commits into
jetlinks:2.11from
PengyuDeng:feature

Conversation

@PengyuDeng

Copy link
Copy Markdown
Contributor
  • 在application.yml和application-default.yml中新增TIMESCALEDB_FUNCTION_SCHEMA配置项
  • 修改TimescaleDBCreateTableSqlBuilder类,移除构造函数中的schema参数
  • 更新创建超表和保留策略的SQL语句,使用functionSchema替代原有schema
  • 在TimescaleDBTimeSeriesManager中注入TimescaleDBProperties并设置FunctionSchema特性
  • 调整时间分组列的创建逻辑,支持传入functionSchema参数
  • 引入FunctionSchema类管理TimescaleDB相关的函数位置信息

- 在application.yml和application-default.yml中新增TIMESCALEDB_FUNCTION_SCHEMA配置项
- 修改TimescaleDBCreateTableSqlBuilder类,移除构造函数中的schema参数
- 更新创建超表和保留策略的SQL语句,使用functionSchema替代原有schema
- 在TimescaleDBTimeSeriesManager中注入TimescaleDBProperties并设置FunctionSchema特性
- 调整时间分组列的创建逻辑,支持传入functionSchema参数
- 引入FunctionSchema类管理TimescaleDB相关的函数位置信息
/**
* TimescaleDB超表函数所在的位置
*/
private String functionSchema = "public";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认应该为null. 为null时使用schema, 否则只配置了schema的情况下, 可能有问题.


return NativeSelectColumn
.of("time_bucket('" + unit + "',timestamp)");
.of(functionSchema + ".time_bucket('" + unit + "',timestamp)");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

括起来更好? 有的schema 有- 可能会有问题.


@AllArgsConstructor(staticName = "of")
@Getter
public class FunctionSchema implements Feature, FeatureType {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建立直接传 TimescaleDBProperties 便于后续拓展

request.getFrom().getTime(),
request.getInterval()
request.getInterval(),
database.getMetadata().getTable(metric).get().getFeatureNow(FunctionSchema.ID).getFunctionSchema()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

某些特殊情况下没创建表时会产生错误.

.ddl()
.createOrAlter(tableName)
.custom(table -> {
table.addFeature(FunctionSchema.of(timescaleDBProperties.getFunctionSchema()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议创建database 时直接放到 database或者schema中

* TimescaleDB超表函数所在的位置
*/
private String functionSchema = "public";
private String functionSchema = this.schema;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样并不准确. 重写get方法更合适?

String interval = createHypertable.getInterval().getNumber().intValue() + " "
+ createHypertable.getInterval().getUnit().name().toLowerCase();
String functionSchema = table.getFeatureNow(FunctionSchema.ID)
String functionSchema = table.getSchema()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接 table.findFeature就行了?

@zhou-hao
zhou-hao merged commit deff207 into jetlinks:2.11 Nov 5, 2025
2 of 3 checks passed
@PengyuDeng
PengyuDeng deleted the feature branch November 5, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants